load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_license//rules:license.bzl", "license")

license(
    name = "license",
    license_kinds = ["@rules_license//licenses/spdx:MIT"],
    license_text = "LICENSE",
)

# Set this to True enable minitrace macros by adding the following flag to your .bazelrc or passing
# to the bazel commandline: --@minitrace//:mtr_enable
bool_flag(
    name = "mtr_enable",
    build_setting_default = False,
)

config_setting(
    name = "mtr_enable_setting",
    flag_values = {":mtr_enable": "True"},
)

cc_library(
    name = "minitrace",
    srcs = ["minitrace.c"],
    hdrs = ["minitrace.h"],
    defines = select({
        ":mtr_enable_setting": ["MTR_ENABLED"],
        "//conditions:default": [],
    }),
    includes = ["."],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "minitrace_test",
    srcs = ["minitrace_test.cpp"],
    visibility = ["//visibility:public"],
    deps = [":minitrace"],
)

cc_binary(
    name = "minitrace_test_mt",
    srcs = ["minitrace_test_mt.cpp"],
    linkopts = ["-pthread"],
    visibility = ["//visibility:public"],
    deps = [":minitrace"],
)
